package feeinterface.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.ulwx.tool.DbUtils;
import feeinterface.modeldb.BaseBlackList;
import feeinterface.modeldb.BaseImsiPhone;

public class BaseBlackListDao {

	/**
	 * 判断该手机号码,IMSI和MobileID是否为黑名单 2010-12-22
	 * 修改：2010-12-30，原来的方法写在BaseImsiPhoneDao类中是错误 的，这里纠正过来!
	 * 
	 * @param areaID
	 * @return
	 * @throws Exception
	 */
	public static boolean isBlackList(String phone, String imsi)
			throws Exception {
		boolean isBlack = isBlackList(phone);

		if (!isBlack) {

			BaseImsiPhone bp = BaseImsiPhoneDao.getPhoneBy(imsi);
			if (bp != null) {
				phone = bp.getPhone();
				isBlack = isBlackList(phone);
			}
		}

		return isBlack;
	}

	public static boolean isBlackList(String phone) throws Exception {
//		DataBase db = DataBaseFactory.getDataBase();
		Map<Integer, Object> map = new HashMap<Integer, Object>();
		String sql = "";
		// boolean dbReconnect = false;
		if (phone.length() > 10) {
			sql = "SELECT * FROM BaseBlackList WHERE phone = ?";
			map.put(1, phone);
			List<BaseBlackList> list = DbUtils.doQueryClass(null,BaseBlackList.class,
					sql, map);
			if (list != null && list.size() >= 1) {
				return true;
			}

		}
		return false;
	}

	public static void main(String[] args) throws Exception {
		boolean b = BaseBlackListDao.isBlackList("", "");
		System.out.println(b);

	}

}
